﻿if(Tipel.Module == null) Tipel.Module = function(creater){
    var $ = this;
    var Creater = creater;
    
    var LastContNode = null;
    var items = null;
    function Items(){
        if(items != null) return items;
        if(Creater == null || Creater.tpl == null) return null;
        var str = Creater.tpl.Attrs.Get("Items");
        if(str == null || str.length < 1) return null;
        var arr = str.split(",");
        if(arr == null || arr.length < 1) return null;
        items = new Array();
        for(var i=0; i<arr.length; i++){
            str = arr[i];
            if(str == null || str.length < 1) continue;
            str = str.Trim();
            str = $$.Node(str);
            if(str == null) continue;
            items[items.length] = str;
        }
        return items;
    };
    
    $.click = function(evt, node) {
        node = $$.EvtNode(node, evt); if(node == null) return true;
        var n = null;
        var cn = null;
        var ncn = "ModuleCardSel";
        if(Items() != null && items.length > 0){
            for(var i=0; i<items.length; i++){
                n = items[i];
                if(i == 0 && n == node) ncn = "ModuleCardSel0";
                cn = n.className;
                if(cn == null || cn.length < 1) continue;
		        if(cn.match(/ModuleCardSel\d*/i)) n.className = cn.replace(/ModuleCardSel\d*/gi,"ModuleCard_normal");
		        if(LastContNode == null && n.tpl != null){
		            n = n.tpl.Attrs.Node("Refer");
		            if(n != null) n.style.display = "none";
		        }
            }
        }
        cn = node.className;
        if(cn != null && cn.length > 0) node.className = cn.replace(/ModuleCard_\S+/gi, ncn)
        if(LastContNode != null) LastContNode.style.display = "none";
        if(node.tpl != null){
            n = node.tpl.Attrs.Node("Refer");
            if(n != null) n.style.display = "block";
            LastContNode = n;
        }
        return true;
    };
};
Tipel.Module.prototype = $$.Events;